package cn.xiaopengstack.types.config;

import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Map;

/**
 * @author jiangyangang
 */
@Configuration
@EnableConfigurationProperties(NotifyConfigProperties.class)
public class NotifyConfig {

    @Bean
    public NotifyConfigHandle notifyConfigHandle(NotifyConfigProperties notifyConfigProperties){
        return new NotifyConfigHandle(notifyConfigProperties);
    }


    public static class NotifyConfigHandle {
        private final NotifyConfigProperties notifyConfigProperties;

        public NotifyConfigHandle(NotifyConfigProperties notifyConfigProperties) {
            this.notifyConfigProperties = notifyConfigProperties;
        }

        /**
         * 获取指定场景和类型的配置
         * @param scene 场景名称
         * @param type 配置类型
         * @return 配置Map
         */
        public Map<String, Object> getSceneConfig(String scene, String type) {
            return notifyConfigProperties.getSceneConfig(scene, type);
        }

        public String getTopic(String scene){
            return (String) notifyConfigProperties.getConfigValue(scene, "mq", "topic");
        }
    }
}
